package com.itheima.prize.commons.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.prize.commons.constant.SystemConstants;
import com.itheima.prize.commons.db.entity.CardUser;
import com.itheima.prize.commons.db.entity.ViewCardUserHit;
import com.itheima.prize.commons.db.service.ViewCardUserHitService;
import com.itheima.prize.commons.db.mapper.ViewCardUserHitMapper;
import com.itheima.prize.commons.utils.ApiResult;
import com.itheima.prize.commons.utils.PageBean;
import org.springframework.stereotype.Service;

/**
 * @author shawn
 * @description 针对表【view_card_user_hit】的数据库操作Service实现
 * @createDate 2023-12-26 11:58:48
 */
@Service
public class ViewCardUserHitServiceImpl extends ServiceImpl<ViewCardUserHitMapper, ViewCardUserHit>
        implements ViewCardUserHitService {

    /**
     * 根据用户信息查询我的奖品
     */
    @Override
    public ApiResult<PageBean<ViewCardUserHit>> getPrizeByUserInfo(CardUser user, int gameId, int curPage, int limit) {

        Page<ViewCardUserHit> page = new Page<>(curPage, limit);
        LambdaQueryWrapper<ViewCardUserHit> queryWrapper = new LambdaQueryWrapper<>();

        if (gameId != -1) {
            // 查询单个活动信息
            queryWrapper.eq(ViewCardUserHit::getGameid, gameId);
        }

        queryWrapper.eq(ViewCardUserHit::getUserid, user.getId());
        Page<ViewCardUserHit> userHitPage = this.page(page, queryWrapper);
        PageBean<ViewCardUserHit> hitPageBean = new PageBean<>(userHitPage);

        return ApiResult.success(SystemConstants.OPERATION_SUCCESS, hitPageBean);
    }

    /**
     * 根据活动id查询中奖列表
     */
    @Override
    public ApiResult<PageBean<ViewCardUserHit>> getHitByGameId(int gameId, int currPage, int limit) {

        Page<ViewCardUserHit> userHitPage = new Page<>(currPage, limit);
        LambdaQueryWrapper<ViewCardUserHit> queryWrapper = new LambdaQueryWrapper<ViewCardUserHit>()
                .eq(ViewCardUserHit::getGameid, gameId);

        Page<ViewCardUserHit> page = this.page(userHitPage, queryWrapper);
        PageBean<ViewCardUserHit> hitPageBean = new PageBean<>(page);
        return ApiResult.success(SystemConstants.OPERATION_SUCCESS, hitPageBean);
    }

}




